require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')
require('../libs/iconfont/iconfont.css')
require('../css/mine.less')

const utilButtomNav = require('../util/util')

const axios = require('axios')

const weui = require('weui.js')

document.addEventListener('DOMContentLoaded', function () {
    const rank = document.querySelector('.rank')
    const sign = document.querySelector('#sign')
    const serUrl = 'http://139.9.177.51:8099'
    const mysportsBadge = '/users/mysportsBadge'
    const userId = localStorage.getItem('userId')
    console.log(userId);
    //引入组件
    utilButtomNav.ButtomNav('mine')

    //我的页面数据数据渲染
    axios.get(serUrl + mysportsBadge, {
        params: {
            userId: userId
        }
    }).then(function (res) {
        console.log(res);
        // 用户名
        account.textContent = res.data.data.user.nickname
        // console.log(res.data.data.sign);

        // 头像
        if (res.data.data.user.imgurl != null) {
            imgurl.src = res.data.data.user.imgurl
        }

        // 个性签名
        if (res.data.data.user.sign != null) {
            sign.textContent = res.data.data.user.sign
        } else {
            sign.textContent = '这个人很懒，什么都没留下！'
        }

        //动态
        dynamicCount.textContent = `${res.data.data.dynamicCount}条`

        //总运动
        times.textContent = res.data.data.sports.times

        // 总消耗
        calorie.textContent = res.data.data.sports.calorie
    })

    //点击退出按钮清空本地存储的userId并跳转至登陆界面
    out.addEventListener('click',function(){
        localStorage.removeItem('userId')
        location.href = './login.html'
    })

    //点击跳转至修改信息界面
    topUser.addEventListener('click',function(){
        location.href = './personalData.html'
    })
    //点击跳转至运动信息界面
    sportsData.addEventListener('click',function(){
        location.href = './sportsData.html'
    })
    //点击跳转至运动信息界面
    myBadge.addEventListener('click',function(){
        location.href = './badge.html'
    })

})
